// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   pagesFourty.java

package include.list_page;

import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;

public class pagesFourty extends TagSupport
{

	private ResultSet rs;
	private String strPage;
	private int PageSize;
	private int RowTotalCount;
	private int PageCount;
	private int intPage;
	private int i;
	private int line;
	private int index;
	private int last;

	public pagesFourty()
	{
		RowTotalCount = 0;
		PageCount = 0;
		line = 0;
	}

	public ResultSet getrs()
	{
		return rs;
	}

	public void setrs(ResultSet rs)
	{
		this.rs = rs;
	}

	public String getstrPage()
	{
		return strPage;
	}

	public void setstrPage(String strPage)
	{
		this.strPage = strPage;
	}

	public int getPageSize()
	{
		return PageSize;
	}

	public void setPageSize(int PageSize)
	{
		this.PageSize = PageSize;
	}

	public int doStartTag()
		throws JspException
	{
		if (strPage == null || strPage.equals("") || strPage.length() > 9)
		{
			strPage = "1";
			intPage = 1;
		} else
		{
			intPage = Integer.parseInt(strPage);
			if (intPage < 1)
				intPage = 1;
		}
		if (rs != null)
		{
			boolean goorback = false;
			try
			{
				goorback = rs.next();
			}
			catch (SQLException sqlexception) { }
			if (goorback)
			{
				try
				{
					rs.last();
					RowTotalCount = rs.getRow();
					PageCount = ((RowTotalCount + 40) - 1) / 40;
					if (intPage > PageCount)
						intPage = PageCount;
					rs.absolute((intPage - 1) * 40 + 1);
				}
				catch (SQLException sqlexception1) { }
				pageContext.setAttribute("intPage", (new Integer(intPage)).toString());
				pageContext.setAttribute("PageCount", (new Integer(PageCount)).toString());
				index = (intPage - 1) * 40 + 1;
				last = intPage * 40 + 1;
				return 1;
			}
		}
		return 0;
	}

	public int doAfterBody()
		throws JspException
	{
		try
		{
			rs.next();
		}
		catch (SQLException sqlexception) { }
		index++;
		return index >= last || index > RowTotalCount ? 0 : 2;
	}
}
